package com.baili.controller.operater;

import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.baili.dto.BaseTransferEntity;
import com.baili.dto.Call;
import com.baili.dto.Check;
import com.baili.dto.ProductOrder;
import com.baili.dto.Sampling;
import com.baili.dto.SelectUserInput;
import com.baili.service.admin.AdminService;
import com.baili.service.inspector.InspectorService;
import com.baili.service.operater.OperaterService;
import com.baili.service.productionorder.ProductionOrderService;
import com.baili.service.user.UserService;
import com.baili.util.MobileConfig;
import com.baili.util.StringUtil;

/**
 * @author iceX
 * @version 创建时间：2016年3月30日 下午2:19:29
 * @Name: OperaterController.java操作人员
 */
@Controller
@RequestMapping(value = "")
public class OperaterController {

	private static Logger log = Logger.getLogger(OperaterController.class);
	@Autowired
	private OperaterService operaterService;
	@Autowired
	private AdminService adminService;
	@Autowired
	private InspectorService inspectorService;
	@Autowired
	private ProductionOrderService productionOrderService;
	@Autowired
	private UserService userService;

	/**
	 * 操作人员-现场呼叫-现场呼叫记录
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getCallLog")
	@ResponseBody
	public BaseTransferEntity getCallLog(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			int id = Integer.parseInt(request.getParameter("userId"));
			ProductOrder productOrder = new ProductOrder();
			productOrder.setId(id);
			// 获取列表数据
			List lst = operaterService.getCallLog(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-现场呼叫-现场呼叫记录(详情)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getCallLogById")
	@ResponseBody
	public BaseTransferEntity getCallLogById(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			int id = Integer.parseInt(request.getParameter("id"));
			// 获取列表数据
			List<Map<String, Object>> lst = operaterService.getCallLogById(id);

			for (Map<String, Object> map : lst) {

				Date callTime = sdf.parse(map.get("callTime").toString());
				String waitingTime = "";
				long date1 = callTime.getTime();
				long date2 = (new Date()).getTime();

				long timeDifference = (date2 - date1);

				long days = timeDifference / (24 * 60 * 60 * 1000);
				long hours = (timeDifference % (24 * 60 * 60 * 1000))
						/ (60 * 60 * 1000);
				long minute = ((timeDifference % (24 * 60 * 60 * 1000)) % (60 * 60 * 1000))
						/ (60 * 1000);
				long second = (((timeDifference % (24 * 60 * 60 * 1000)) % (60 * 60 * 1000)) % (60 * 1000)) / (1000);

				if (days > 0) {

					waitingTime = days + "天" + hours + "小时" + minute + "分钟";
				} else if (days <= 0 && hours > 0) {

					waitingTime = hours + "小时" + minute + "分钟";

				} else if (days <= 0 && hours <= 0) {

					waitingTime = minute + "分钟";
				}
				map.put("waitingTime", waitingTime);

				// 0表示图片浏览1表示视频浏览
				List<Map<String, Object>> pList = new ArrayList<Map<String, Object>>();

				pList = inspectorService.getCallOrDefectAndPictureOrVedio(id,
						0, 0);

				map.put("imageUrls", pList);

				List<Map<String, Object>> vList = new ArrayList<Map<String, Object>>();

				vList = inspectorService.getCallOrDefectAndPictureOrVedio(id,
						1, 0);

				map.put("videoUrls", vList);
			}

			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-现场呼叫-事件主题查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getEventTypeList")
	@ResponseBody
	public BaseTransferEntity getEventTypeList(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			// 获取列表数据
			Call call = new Call();

			String userId = request.getParameter("userId");

			call.setUserId(Integer.parseInt(userId));

			List<Map<String, Object>> lst = operaterService
					.getCallTypeByUser(call);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 检验人员-现场呼叫-提交事件
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/insertEventType")
	@ResponseBody
	public BaseTransferEntity insertEventType(
			@RequestParam("uploadfile") CommonsMultipartFile[] files,
			HttpServletRequest request) throws IOException {

		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		try {
			Call call = new Call();

			String eventTopicId = request.getParameter("eventTopicId");

			String eventDescription = request.getParameter("eventDescription");

			Date callTime = new Date();

			String userid = request.getParameter("userId");

			String fileName = "";
			// MultipartFile是对当前上传的文件的封装，当要同时上传多个文件时，可以给定多个MultipartFile参数(数组)
			if (files != null) {

				// fileName =
				// adminService.uploadfiles(files,request.getContextPath());
			}

			call.setCallPersonId(Integer.parseInt(userid));

			call.setCallTime(sdf.format(callTime));

			call.setCount(0);

			call.setDealType(0);

			call.setEventDescription(eventDescription);

			call.setEventTopicId(Integer.parseInt(eventTopicId));

			call.setOverPersonId(0);

			call.setPictureName(fileName);

			call.setUserId(Integer.parseInt(userid));

			call.setViewName(fileName);
			// 插入
			// operaterService.insertEventType(call);

			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("addEventType 提交事件--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		return baseTransferEntity;
	}

	/**
	 * 操作人员-呼叫设置更新状态
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @return
	 */
	@RequestMapping(value = "/service/updatState")
	@ResponseBody
	public BaseTransferEntity updatState(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String state = request.getParameter("state");
			// String operater =request.getParameter("operater");
			String id = request.getParameter("id");
			if (state != null && id != null) {
				operaterService.updateState(Integer.parseInt(state),
						Integer.parseInt(id));
				baseTransferEntity.setIsSuccess(0);
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.success"));
			} else {
				baseTransferEntity.setIsSuccess(1);
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				return baseTransferEntity;
			}
		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
		}
		return baseTransferEntity;
	}

	/**
	 * 操作人员-质检分析
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @return
	 */
	@RequestMapping(value = "/service/checkedAnalysis")
	@ResponseBody
	public BaseTransferEntity checkedAnalysis(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {

			String startTime = request.getParameter("startTime");
			String overTime = request.getParameter("overTime");
			String productCode = request.getParameter("productCode");
			String userId = request.getParameter("userId");

			ProductOrder productOrder = new ProductOrder();

			productOrder.setStartTime(startTime);
			
			if (!StringUtil.isEmpty(overTime)) {
				
				Date overTimeDate = StringUtil.parseDate2(overTime, "yyyy-MM-dd");
				
				Date overTimeDateAdd = StringUtil.addDay(overTimeDate, 1);
				
				productOrder.setOverTime(StringUtil.date2String(overTimeDateAdd));
				
			}else {
				
				productOrder.setOverTime(overTime);
				
			}

			// productOrder.setOverTime(overTime);

			productOrder.setProductCode(productCode);

			productOrder.setUserId(Integer.parseInt(userId));

			List lst = operaterService.checkedAnalysis(productOrder);

			if (lst == null || lst.size() < 1) {

				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.success"));

				baseTransferEntity.setData(null);

				baseTransferEntity.setIsSuccess(1);
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));

			baseTransferEntity.setData(lst);

			baseTransferEntity.setIsSuccess(1);

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
		}
		return baseTransferEntity;
	}
	/**
	 * 抽检-抽检的统计列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getSamplingStatistic")
	@ResponseBody
	public BaseTransferEntity getSamplingStatistic(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			
			String startTime = request.getParameter("startTime");
			String overTime = request.getParameter("overTime");
			String styleNo = request.getParameter("styleNo");
			String checkName = request.getParameter("checkName");//这个字段

			if(!StringUtil.isEmpty(overTime)){
				
				Date overTimeDate = StringUtil.parseDate2(overTime, "yyyy-MM-dd");
				
				overTime = StringUtil.date2String(StringUtil.addDay(overTimeDate, 1));
			}
			
			Sampling sampling = new Sampling();
			
			sampling.setStartTime(startTime);
			
			sampling.setOverTime(overTime);
			
			sampling.setStyleNo(styleNo);
			
			if(!StringUtil.isEmpty(checkName)){
				
				checkName = StringUtil.decodeUnicode(checkName);
				
			}
			
			sampling.setCheckName(checkName);
			
			//获取返回状态
			List lst = inspectorService.getSamplingStatistic(sampling);
			
			if (lst == null || lst.size() < 1) {
				
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.success"));
				
				baseTransferEntity.setData(null);
				
				baseTransferEntity.setIsSuccess(1);
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			
			baseTransferEntity.setData(lst);
			
			baseTransferEntity.setIsSuccess(1);
			
		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
		}
		return baseTransferEntity;
	}

	/**
	 * 操作人员-质检分析
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @return
	 */
	@RequestMapping(value = "/service/getFedAnalysis")
	@ResponseBody
	public BaseTransferEntity getFedAnalysis(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			String userId = request.getParameter("userId");

			ProductOrder productOrder = new ProductOrder();

			productOrder.setUserId(Integer.parseInt(userId));

			List lst = operaterService.getFedAnalysis(productOrder);

			if (lst == null || lst.size() < 1 || lst.get(0) == null) {

				//baseTransferEntity.setTotalCount("");

				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));

				baseTransferEntity.setData(null);

				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));

			baseTransferEntity.setData(lst);

			baseTransferEntity.setIsSuccess(1);

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
		}
		return baseTransferEntity;
	}

	/**
	 * 操作人员-质检分析
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @return
	 */
	@RequestMapping(value = "/service/updateFedAnalysis")
	@ResponseBody
	public BaseTransferEntity updateFedAnalysis(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			String id = request.getParameter("id");

			// String feed =request.getParameter("feed");
			
			String userId = request.getParameter("userId");

			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));

			Map<String, Object> processNameMap = processNameLst.get(0);

			String processName = processNameMap.get("processName").toString();
			
			int checkProcess = 0;
			
			if(processName.equals("开料")){
				
				checkProcess = 1;
				
			}else if(processName.equals("制帮")){
				
				checkProcess = 2;
				
			}else if(processName.equals("中底")){
				
				checkProcess = 3;
				
			}else if(processName.equals("成型底")){
				
				checkProcess = 4;
				
			}else if(processName.equals("前段") || processName.equals("中段") || processName.equals("后段")){
				
				checkProcess = 5;
				
			}

			operaterService.updateFedAnalysis(Integer.parseInt(id), 1,checkProcess);

			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
		}
		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-预警
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getwarning")
	@ResponseBody
	public BaseTransferEntity getwarning(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			String productTeamId = request.getParameter("productTeamId");
			String scheduleNo = request.getParameter("scheduleNo");
			String userId = request.getParameter("userId");

			String flag = "<>";
			ProductOrder productOrder = new ProductOrder();

			productOrder.setProductTeamId(Integer.parseInt(productTeamId));

			productOrder.setScheduleNo(scheduleNo);
			
			productOrder.setOperatorId(Integer.parseInt(userId));

			List<Map<String, Object>> processNameLst = userService
					.getProcessNameByUser(Integer.parseInt(userId));

			Map<String, Object> processNameMap = processNameLst.get(0);

			String processName = processNameMap.get("processName").toString();

			// String processName =
			// processNameMap.get("processName").toString();

			productOrder.setProcessName(processName);
			
			productOrder.setRemarks(processName);

			productOrder.setFlag(flag);
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

			if (processName.equals("开料")) {

				productOrder.setProcessName(processName);

				List<Map<String, Object>> ptLst = this.operaterService
						.getProductTeamsByProductTeamId(productOrder);

				if (ptLst != null && ptLst.size() > 0) {

					for (Map<String, Object> ptMap : ptLst) {

						int sProductTeamId = Integer.parseInt(ptMap.get("id")
								.toString());

						ProductOrder order = new ProductOrder();

						if (StringUtil.isEmpty(scheduleNo)) {

							productOrder.setScheduleNo(null);
						}

						order = productOrder;

						order.setProductTeamId(sProductTeamId);

						order.setKzType(1);

						List fwLst = operaterService.getFinishWorkYOrN(order);

						if (fwLst != null && fwLst.size() > 0) {

							list.addAll(fwLst);
						}
					}
				}

			} else {

				if (processName.equals("制帮")) {

					productOrder.setProcessName(processName);

					productOrder.setFlag(flag);

					productOrder.setKzType(2);
				}

				list = operaterService.getFinishWorkYOrN(productOrder);

			}

			// if(processName.equals("开料")){
			//
			// productOrder.setKzType(1);
			//
			// }else if(processName.equals("制帮")){
			//
			// productOrder.setKzType(2);
			// }
			//
			// productOrder.setProcessName(processName);
			//
			// List<Map<String, Object>> warning =
			// operaterService.getWarning(productOrder);

			for (Map<String, Object> map : list) {

				Date overTime = sdf.parse(map.get("overTime").toString());

				long date1 = overTime.getTime();

				long date2 = (new Date()).getTime();

				long timeDifference = (date2 - date1);

				double days = ((double) timeDifference / (24 * 60 * 60 * 1000));

				int returnDay = (int) Math.ceil(days)-1;

				if (days < 0) {

					if (days > -1) {

						returnDay = -1000000;

					}

				} else if (days >= 0) {

					if (days < 1) {

						returnDay = 1000000;

					}

				}

				map.put("warningRank", returnDay);

			}
			// 返回列表数据
			if (list == null || list.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(list);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-未完成或已完成
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getNofinishwork")
	@ResponseBody
	public BaseTransferEntity getNofinishwork(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			ProductOrder productOrder = new ProductOrder();

			String productTeamId = request.getParameter("productTeamId");
			String scheduleNo = request.getParameter("scheduleNo");

			String flag = request.getParameter("flag");
			String operatorId = request.getParameter("userId");

			productOrder.setProductTeamId(Integer.parseInt(productTeamId));

			productOrder.setScheduleNo(scheduleNo);

			productOrder.setOperatorId(Integer.parseInt(operatorId));

			List<Map<String, Object>> processNameLst = userService
					.getProcessNameByUser(Integer.parseInt(operatorId));

			Map<String, Object> map = processNameLst.get(0);

			String processName = map.get("processName").toString();

			productOrder.setProcessName(processName);

			productOrder.setRemarks(processName);

			productOrder.setFlag(flag);

			List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();

			if (processName.equals("开料")) {

				productOrder.setProcessName(processName);

				List<Map<String, Object>> ptLst = this.operaterService
						.getProductTeamsByProductTeamId(productOrder);

				if (ptLst != null && ptLst.size() > 0) {

					for (Map<String, Object> ptMap : ptLst) {

						int sProductTeamId = Integer.parseInt(ptMap.get("id")
								.toString());

						ProductOrder order = new ProductOrder();

						if (StringUtil.isEmpty(scheduleNo)) {

							productOrder.setScheduleNo(null);
						}

						order = productOrder;

						order.setProductTeamId(sProductTeamId);

						order.setKzType(1);

						List fwLst = operaterService.getFinishWorkYOrN(order);

						if (fwLst != null && fwLst.size() > 0) {

							list.addAll(fwLst);
						}
					}
				}

			} else {

				if (processName.equals("制帮")) {

					productOrder.setProcessName(processName);

					productOrder.setFlag(flag);

					productOrder.setKzType(2);
				}

				list = operaterService.getFinishWorkYOrN(productOrder);

			}
			
			// 返回列表数据
			if (list == null || list.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(list);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-未完成或已完成
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getProcessNameByProductTeam")
	@ResponseBody
	public BaseTransferEntity getProcessNameByProductTeam(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			ProductOrder productOrder = new ProductOrder();

			String productTeamId = request.getParameter("productTeamId");
			String userId = request.getParameter("userId");

			productOrder.setProductTeamId(Integer.parseInt(productTeamId));

			List<Map<String, Object>> processNameLst = userService
					.getProcessNameByUser(Integer.parseInt(userId));

			// 返回列表数据
			if (processNameLst == null || processNameLst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(processNameLst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-未完成-轮次
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getroundDetails")
	@ResponseBody
	public BaseTransferEntity getroundDetails(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			String userId = request.getParameter("userId");
			List<Map<String, Object>> processNameLst = userService
					.getProcessNameByUser(Integer.parseInt(userId));

			Map<String, Object> map = processNameLst.get(0);

			String processName = map.get("processName").toString();

			productOrder.setProcessName(processName);
			String flag = request.getParameter("flag");
			productOrder.setFlag(flag);
			productOrder.setProductCode(productCode);
			productOrder.setScheduleNo(scheduleNo);
			List list = operaterService.getRoundDetails(productOrder);
			// 返回列表数据
			if (list == null || list.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(list);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-未完成-轮次
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getroundList")
	@ResponseBody
	public BaseTransferEntity getroundList(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			String flag = request.getParameter("flag");
			productOrder.setFlag(flag);
			productOrder.setScheduleNo(scheduleNo);
			productOrder.setProductCode(productCode);

			String userId = request.getParameter("userId");

			List<Map<String, Object>> processNameLst = userService
					.getProcessNameByUser(Integer.parseInt(userId));

			Map<String, Object> map = processNameLst.get(0);

			String processName = map.get("processName").toString();

			productOrder.setProcessName(processName);
			productOrder.setRemarks(processName);
			;

			List list = operaterService.getroundList(productOrder);
			// 返回列表数据
			if (list == null || list.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(list);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-未完成-轮次
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getRoundListToSee")
	@ResponseBody
	public BaseTransferEntity getRoundListToSee(HttpServletRequest request,
			HttpServletResponse response) {

		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();

		try {

			ProductOrder productOrder = new ProductOrder();

			String productCode = request.getParameter("productCode");

			String scheduleNo = request.getParameter("scheduleNo");
			
			productOrder.setScheduleNo(scheduleNo);

			productOrder.setProductCode(productCode);

			List<Map<String, Object>> list = operaterService
					.getRoundListToSee(productOrder);

			// 返回列表数据
			if (list == null || list.size() < 1) {

				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));

				baseTransferEntity.setData(null);

				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));

				return baseTransferEntity;
			}

			for (Map<String, Object> map : list) {

				String state = map.get("state").toString();
				String kzType = map.get("kzType").toString();

				if (state.equals("2") || state.equals("3") || state.equals("4") || state.equals("6") || (kzType.equals("1") && state.equals("5"))) {

					map.put("state", 2);
				}
			}

			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));

			baseTransferEntity.setData(list);

			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {

			log.error("--------->" + e.getMessage(), e);

			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));

			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");

			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 计划人员进度查看，单个轮次详情
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getRoundListToSeeDetails")
	@ResponseBody
	public BaseTransferEntity getRoundListToSeeDetails(
			HttpServletRequest request, HttpServletResponse response) {

		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();

		try {

			ProductOrder productOrder = new ProductOrder();

			String id = request.getParameter("id");

			productOrder.setId(Integer.parseInt(id));

			String userId = request.getParameter("userId");

			List<Map<String, Object>> userList = userService
					.getProcessNameByUser(Integer.parseInt(userId));

			List<Map<String, Object>> list = operaterService
					.getRoundListToSeeDetails(productOrder);

			productOrder = productionOrderService.getOrderById(productOrder);

			List<Map<String, Object>> lst = new ArrayList<Map<String, Object>>();

			if (productOrder.getKzType() > 0) {

				if (list != null && list.size() > 0) {
					int count = 0;
					for (Map<String, Object> map : list) {

						if (count == 0) {

							map.put("processName", "开料");

						} else if (count == 1) {

							map.put("processName", "帮面生产");
						}

						lst.add(map);

						count++;
					}
				}

			} else if (productOrder.getStage() > 0) {

				if (list != null && list.size() > 0) {

					int count = 0;
					for (Map<String, Object> map : list) {

						if (count == 0) {

							map.put("processName", "前段");

						} else if (count == 1) {

							map.put("processName", "中段");

						} else if (count == 2) {

							map.put("processName", "后段");
						}

						lst.add(map);

						count++;
					}

				} else {

					String processName = userList.get(0).get("processName")
							.toString();

					if (list != null && list.size() > 0) {

						if (userList != null && userList.size() > 0) {

							if (processName.equals("中底")) {

								for (Map<String, Object> map : list) {

									map.put("processName", "中底");

									lst.add(map);
								}

							} else if (processName.equals("成型底")) {

								for (Map<String, Object> map : list) {

									map.put("processName", "成型底");

									lst.add(map);
								}
							}
						}
					}
				}
			}

			// 返回列表数据
			if (list == null || list.size() < 1) {

				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));

				baseTransferEntity.setData(null);

				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));

				return baseTransferEntity;
			}

			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));

			baseTransferEntity.setData(list);

			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {

			log.error("--------->" + e.getMessage(), e);

			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));

			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");

			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 公司领导-计划进度-进度查看
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getRoundListBySee")
	@ResponseBody
	public BaseTransferEntity getRoundListBySee(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			String flag = request.getParameter("flag");
			productOrder.setFlag(flag);
			productOrder.setScheduleNo(scheduleNo);
			productOrder.setProductCode(productCode);

			List<Map<String, Object>> list = operaterService
					.getroundList(productOrder);

			if (list != null && list.size() > 0) {

				for (Map<String, Object> map : list) {

					Integer.parseInt(map.get("state").toString());

				}

			}

			// 返回列表数据
			if (list == null || list.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(list);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-未完成-轮次-查看领料单
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getpicklists")
	@ResponseBody
	public BaseTransferEntity getpicklists(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			productOrder.setScheduleNo(scheduleNo);
			productOrder.setProductCode(productCode);
			// 获取列表数据
			lst = operaterService.getpicklists(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-未完成-轮次-查看资料
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getdataList")
	@ResponseBody
	public BaseTransferEntity getdataList(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			productOrder.setProductCode(productCode);
			productOrder.setScheduleNo(scheduleNo);
			// 获取列表数据
			lst = operaterService.getdataList(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-质检-查看(已完成)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getCheckSee")
	@ResponseBody
	public BaseTransferEntity getCheckSee(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();

			ProductOrder productOrder = new ProductOrder();

			String id = request.getParameter("id");
			String scheduleNo = request.getParameter("scheduleNo");

			productOrder.setId(Integer.parseInt(id));
			productOrder.setScheduleNo(scheduleNo);
			
			String userId = request.getParameter("userId");
			
			productOrder.setUserId(Integer.parseInt(userId));

			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));

			
			SelectUserInput selectUserInput = new SelectUserInput();
			
			selectUserInput.setId(Integer.parseInt(userId));
			//使用用户的ID查询其所对应的角色类型
			List<Map<String,Object>> roleTypeLst = userService.getRoleTypeByUserId(selectUserInput);
			
			String roleType = "";
			
			if(roleTypeLst != null && roleTypeLst.size() > 0){
				
				roleType = roleTypeLst.get(0).get("roleType").toString();
				
			}
			
			Map<String, Object> processNameMap = processNameLst.get(0);

			String processName = processNameMap.get("processName").toString();
			
			int processId = Integer.parseInt(processNameMap.get("processId").toString());
			
			productOrder.setProcessName(processName);
			
			productOrder.setProcessId(processId);
			
			productOrder.setRemarks(roleType);
			
			if(processName.equals("开料")){
				
				productOrder.setCheckProcess(1);
				
			}else if(processName.equals("制帮")){
				
				productOrder.setCheckProcess(2);
				
			}else if(processName.equals("中底")){
				
				productOrder.setCheckProcess(3);
				
			}else if(processName.equals("成型底")){
				
				productOrder.setCheckProcess(4);
				
			}else if(processName.equals("前段") || processName.equals("中段") || processName.equals("后段")){
				
				productOrder.setCheckProcess(5);
				
			}
			
//			else if(processName.equals("前段")){
//				
//				productOrder.setCheckProcess(5);
//				
//			}else if(processName.equals("中段")){
//				
//				productOrder.setCheckProcess(6);
//				
//			}else if(processName.equals("后段")){
//				
//				productOrder.setCheckProcess(7);
//				
//			}
			// 获取列表数据
			List<Map<String, Object>> lstDefect = operaterService
					.getCheckSee(productOrder);
			
			int defectId = 0;
			
			List<Map<String, Object>> picLst = new ArrayList<Map<String,Object>>();
			List<Map<String, Object>> vdoLst = new ArrayList<Map<String,Object>>();
			
			
			if(productOrder.getCheckProcess() >= 5
					&& productOrder.getRemarks().equals("O")){
				
				List<Map<String, Object>> lstPic = operaterService.getCheckSeeDefectToPicVdo(productOrder);
				
				if(lstPic != null && lstPic.size() > 0){
					
					for(Map<String, Object> picMap : lstPic){
						
						if (picMap.get("pictureName") != null) {
							
							picLst.add(picMap);
						}
					}
				}
				
			}else{
				
				for (Map<String, Object> map : lstDefect) {
					
					productOrder.setCheckId(Integer.parseInt(map.get("id").toString()));
					
					List<Map<String, Object>> lstPic = operaterService.getCheckSeeDefectToPicVdo(productOrder);
					
					if(lstPic != null && lstPic.size() > 0){
						
						for(Map<String, Object> picMap : lstPic){
							
							if (picMap.get("pictureName") != null) {
								
								picLst.add(picMap);
							}
						}
					}
//				if (map.get("pictureName") != null
//						|| map.get("pictureName") != null) {
//
//					defectId = Integer.parseInt(map.get("id").toString());
//
//					break;
//				}
				}
			}

			List<Map<String, Object>> pList = new ArrayList<Map<String, Object>>();

			List<Map<String, Object>> vList = new ArrayList<Map<String, Object>>();
			
			for (Map<String, Object> map : picLst) {

				// 0表示图片浏览1表示视频浏览
				pList.addAll(inspectorService.getDefectAndPictureOrVedio(
						map.get("pictureName").toString(), 0, 1));



				vList.addAll(inspectorService.getDefectAndPictureOrVedio(
						map.get("pictureName").toString(), 1, 1));

			}
			
			for (Map<String, Object> map : lstDefect) {
				
				map.put("imageUrls", pList);
				map.put("videoUrls", vList);
			}

			// 返回列表数据
			if (lstDefect == null || lstDefect.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lstDefect);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-质检-查看(未完成-有缺陷)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getCheckSeeDefect")
	@ResponseBody
	public BaseTransferEntity getCheckSeeDefect(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();

			ProductOrder productOrder = new ProductOrder();

			String id = request.getParameter("id");
			
			String userId = request.getParameter("userId");
			//使用用户的ID查询其所属的工序
			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));
			

			SelectUserInput selectUserInput = new SelectUserInput();
			
			selectUserInput.setId(Integer.parseInt(userId));
			//使用用户的ID查询其所对应的角色类型
			List<Map<String,Object>> roleTypeLst = userService.getRoleTypeByUserId(selectUserInput);
			
			String roleType = "";
			
			if(roleTypeLst != null && roleTypeLst.size() > 0){
				
				roleType = roleTypeLst.get(0).get("roleType").toString();
				
			}
			//将用户的角色类型带到DAO层去
			productOrder.setRemarks(roleType);
			
			Map<String, Object> processNameMap = processNameLst.get(0);

			String processName = processNameMap.get("processName").toString();
			
			int processId = Integer.parseInt(processNameMap.get("processId").toString());
			
			productOrder.setProcessName(processName);
			
			productOrder.setProcessId(processId);
			
			if(processName.equals("开料")){
				
				productOrder.setCheckProcess(1);
				
			}else if(processName.equals("制帮")){
				
				productOrder.setCheckProcess(2);
				
			}else if(processName.equals("中底")){
				
				productOrder.setCheckProcess(3);
				
			}else if(processName.equals("成型底")){
				
				productOrder.setCheckProcess(4);
				
			}else if(processName.equals("前段")){
				
				productOrder.setCheckProcess(5);
				
			}else if(processName.equals("中段")){
				
				productOrder.setCheckProcess(5);
				
			}else if(processName.equals("后段")){
				
				productOrder.setCheckProcess(5);
				
			}

			productOrder.setId(Integer.parseInt(id));
			// 获取列表数据
			lst = operaterService.getCheckSeeDefect(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-已完成的列表-轮次
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getallfinishroundDetails")
	@ResponseBody
	public BaseTransferEntity getallfinishroundDetails(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			productOrder.setProductCode(productCode);
			// 获取列表数据
			lst = operaterService.getallfinishroundDetails(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-已完成-轮次-查看领料单
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getallfinishpicklists")
	@ResponseBody
	public BaseTransferEntity getallfinishpicklists(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			productOrder.setProductCode(productCode);
			// 获取列表数据
			lst = operaterService.getallfinishpicklists(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-已完成-轮次-查看资料
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getallfinishdataList")
	@ResponseBody
	public BaseTransferEntity getallfinishdataList(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			productOrder.setProductCode(productCode);
			// 获取列表数据
			lst = operaterService.getallfinishdataList(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-已完成-轮次-上
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getallfinishroundList")
	@ResponseBody
	public BaseTransferEntity getallfinishroundList(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			productOrder.setProductCode(productCode);
			// 获取列表数据
			lst = operaterService.getallfinishroundList(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-已完成-轮次-下
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getallfinishDetails")
	@ResponseBody
	public BaseTransferEntity getallfinishDetails(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			productOrder.setProductCode(productCode);
			// 获取列表数据
			lst = operaterService.getallfinishDetails(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 操作人员-生产任务-状态更改
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/updateOperationState")
	@ResponseBody
	public BaseTransferEntity updateOperationState(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			ProductOrder productOrder = new ProductOrder();

			String state = request.getParameter("state");
			String userId = request.getParameter("userId");
			String id = request.getParameter("id");

			Check check = new Check();

			check.setCheckPersonId(Integer.parseInt(userId));

			check.setProductId(Integer.parseInt(id));

			List<Map<String, Object>> lst = inspectorService.getCheckId(check);

			if (lst != null && lst.size() > 0) {

				operaterService.deleteCheck(check);

			}

			productOrder.setState(Integer.parseInt(state));

			productOrder.setUserId(Integer.parseInt(userId));

			productOrder.setId(Integer.parseInt(id));

			operaterService.updateOperationState(productOrder);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 呼叫任务个人订制-查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getCallTypeUser")
	@ResponseBody
	public BaseTransferEntity getCallTypeUser(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			Call call = new Call();

			String userId = request.getParameter("userId");

			String id = request.getParameter("id");

			call.setUserId(Integer.parseInt(userId));
			call.setId(Integer.parseInt(id));

			List<Map<String, Object>> lst = operaterService
					.getCallTypeUser(call);

			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 呼叫任务个人订制-添加
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/insertCallTypeUser")
	@ResponseBody
	public BaseTransferEntity insertCallTypeUser(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			Call call = new Call();

			String userId = request.getParameter("userId");
			String callTypeId = request.getParameter("id");

			call.setCallTypeId(Integer.parseInt(callTypeId));

			call.setUserId(Integer.parseInt(userId));

			List<Map<String, Object>> lst = operaterService
					.insertCallTypeUser(call);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 呼叫任务个人订制-删除
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/deleteCallTypeUser")
	@ResponseBody
	public BaseTransferEntity deleteCallTypeUser(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			Call call = new Call();

			String userId = request.getParameter("userId");
			String callTypeId = request.getParameter("callTypeId");

			call.setCallTypeId(Integer.parseInt(callTypeId));

			call.setUserId(Integer.parseInt(userId));

			List<Map<String, Object>> lst = operaterService
					.deleteCallTypeUser(call);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 获得参考资料信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getReferenceMaterial")
	@ResponseBody
	public BaseTransferEntity getReferenceMaterial(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			String finishedProductName = request
					.getParameter("finishedProductName");

			List lst = operaterService
					.getReferenceMaterial(finishedProductName);

			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 按级别查询小组信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getProductTeamsByLevel")
	@ResponseBody
	public BaseTransferEntity getProductTeamsByLevel(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			List lst = new ArrayList();

			Map map1 = new HashMap();
			map1.put("kz", operaterService.getProductTeamsByLevel(2));
			Map map2 = new HashMap();
			map2.put("kz", operaterService.getProductTeamsByLevel(3));

			lst.add(map1);

			lst.add(map2);

			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 获取小组整体信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getProductTeamsAll")
	@ResponseBody
	public BaseTransferEntity getProductTeamsAll(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			List<Map<String, Object>> kllst = operaterService
					.getProductTeamsByLevel(2);

			if (kllst != null && kllst.size() > 0) {

				for (Map<String, Object> klMap : kllst) {

					int id = Integer.parseInt(klMap.get("id").toString());

					ProductOrder productOrder = new ProductOrder();

					productOrder.setProductTeamId(id);

					List zblst = operaterService
							.getProductTeamsByProductTeamId(productOrder);

					if (zblst != null && zblst.size() > 0) {

						klMap.put("kz", zblst);
					}
				}
			}

			// 返回列表数据
			if (kllst == null || kllst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(kllst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

}
